package com.aivin.activity;

import android.os.Bundle;
import android.view.View;

import com.aivin.customView.MyLineSettingView;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.model.LatLng;
import com.aivin.maproutelib.manager.MapRouteManager;
import com.aivin.maproutelib.bean.WkGDmap;
import com.aivin.planningdemo.R;

import java.util.ArrayList;
import java.util.List;

public class MapShowDemoActivity extends Rk3288BaseActivity  {
    private MyLineSettingView mMyLineSettingView;
    private TextureMapView textureMapView;

    @Override
    protected void initActivity(Bundle savedInstanceState) {
        setContentView(R.layout.device_rk3288_main_activity);
        initView(savedInstanceState);
    }

    private void initView(Bundle savedInstanceState) {
        findViewById(R.id.addObstainfo).setOnClickListener(onClickListener);
        textureMapView = findViewById(R.id.textureMapView);

        WkGDmap wkGDmap = new WkGDmap(textureMapView, savedInstanceState, this);

        mMyLineSettingView = findViewById(R.id.bar_right_way_line_view);
        mMyLineSettingView.initMapObject(MyApplication.context, wkGDmap, textureMapView );
    }


    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.getId() == R.id.addObstainfo) {

                List<LatLng> obstacleLatlngs = new ArrayList<>();
                obstacleLatlngs.add(new LatLng(22.888467, 113.400935));
                obstacleLatlngs.add(new LatLng(22.888449, 113.400713));
                obstacleLatlngs.add(new LatLng(22.88848, 113.400584));
                obstacleLatlngs.add(new LatLng(22.888238, 113.400607));

                // todo 增加障碍物区
                List<LatLng> obstacleLatlngs2 = new ArrayList<>();
                obstacleLatlngs2.add(new LatLng(22.888535 , 113.399991));
                obstacleLatlngs2.add(new LatLng(22.888354 , 113.400388));
                obstacleLatlngs2.add(new LatLng(22.888262 , 113.400161));
                obstacleLatlngs2.add(new LatLng(22.888418 , 113.399979));


                List<LatLng> obstacleLatlngs3 = new ArrayList<>();
                obstacleLatlngs3.add(new LatLng(22.888939 , 113.400015));
                obstacleLatlngs3.add(new LatLng(22.888932,  113.400341));
                obstacleLatlngs3.add(new LatLng(22.888711 , 113.400305));
                obstacleLatlngs3.add(new LatLng( 22.888753 , 113.400053));


                List< List<LatLng> > list= new ArrayList<>() ;
                list.add(obstacleLatlngs) ;
                list.add(obstacleLatlngs2) ;
                list.add(obstacleLatlngs3) ;

                MapRouteManager.getInstance().addObstacle2List(list);


            }
        }
    };


    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        textureMapView.onSaveInstanceState(outState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        textureMapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        textureMapView.onPause();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mMyLineSettingView != null) {
            mMyLineSettingView.clearMapRouteManager();
        }

        if (textureMapView != null) {
            textureMapView.onDestroy();
        }
    }
}

